<%@ page contentType="text/event-stream" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%
 response.setHeader("Access-Control-Allow-Origin", "*");
 String lastEventId = request.getHeader("Last-Event-ID");
 System.out.println("last eventId : " + lastEventId);
 
 List<String> msgList = null;
 Object msgListObj = application.getAttribute("msgList");
 if(msgListObj != null){
  msgList = (List<String>)msgListObj;
 }
 List<String> newMsgList = msgList;
 
 if(msgList != null){
  newMsgList = (List<String>)msgList;
  if(lastEventId == null){
   lastEventId = msgList.size() + "";
  }
  newMsgList = msgList.subList(Integer.parseInt(lastEventId), msgList.size());
 
  for(String msg : newMsgList){
   out.println("data: " + msg + "\n");
  }
 }
 
 int eventId = (msgList == null) ? 0 : msgList.size();
 out.println("id: " + eventId);
 out.println("retry: " + 1000);
%>